$(document).ready(function(){
    //page members/oauth_setname submit button click
    $("#oauth_setname_submit").click(function(){
        $.getJSON($("#oauth_setname_form").attr('action'), $("#oauth_setname_form").serialize(), function(json) {
                if(json._status)
                {
                    alert('设置成功，现在将会跳转到用户首页');
                    window.location.href = '/members/index';
                }
                else
                {
                    alert(json.msg);
                }
        });
    });
    $("#common_register_form").validate({
        submitHandler:function(form){
            $.getJSON($(form).attr('action'), $(form).serialize(), function(json, textStatus) {
                if(json._status)
                {
                    alert('注册成功，现在将会跳转到用户首页');
                    window.location.href = '/members/index';
                }
                else
                {
                    alert(json.msg);
                }
            });
        },
        rules : {
            username : {
                required : true,
                remote : '/members/check_username'
            },
            email : {
                required: true,
                email: true
            },
            password : {
                        required: true,
                        minlength: 5
                    },
            repassword : {
                        required: true,
                        equalTo: "input[name='password']"
                    },
            agree : "required"
        },
        messages: {
            username: {
                required: "用户名不可以为空"
            },
            password: {
                required: "请输入密码",
                minlength: "密码至少需要5个字符"
            },
            repassword: {
                required: "请再次输入密码",
                equalTo: "2次填写的密码不一致"
            },
            email: "请输入正确的Email地址",
            agree: "要注册本站，您必须接受我们的<a href=\"/members/agreement\" target=\"_blank\">用户协议</a>"
        },
        errorElement:'span',
        errorClass:'field_info'
    });
});